<?php
include_once("XL_Database/database.php");
class sanpham
{
    function sanpham()
    {
        //do something    
    }
    
    function Lay_Thong_Tin_San_Pham()
    {
        $sql="select * from sanpham ";
        $xldata = new database();
        $kq=$xldata->ExcuteObjectList($sql);
        return $kq;
    }
    
    function Lay_Thong_Tin_Chi_Tiet($Ma_San_Pham)
    {
        $sql="select * from sanpham where ma_san_pham=$Ma_San_Pham";
        $xldata = new database();
        $kq=$xldata->ExcuteObject($sql);
        return $kq;
    }
    
    function Them_San_Pham($Ten_San_Pham,
$Hinh ,
$Mo_Ta ,
$Nguoi_Dang ,
$Danh_Gia ,
$link ,
$Ma_Loai ,
$code ,
$yeucau)
    {
        $sql="INSERT INTO  san_pham (
Ma_San_Pham,
Ten_San_Pham,
Hinh,
Mo_Ta ,
Nguoi_Dang ,
Danh_Gia ,
link ,
Ma_Loai ,
code,
yeucau
)
VALUES (
NULL ,  $Ten_San_Pham,  $Hinh,  $Mo_Ta,  $Nguoi_Dang,  $Danh_Gia,  $link, $Ma_Loai,  $code,  $yeucau
)";
        $xldata = new database();
        $kq=$xldata->ExcuteNonquery($sql);
        return $kq;
    }
    
    function Sua_San_Pham($Ma_San_Pham,$Ten_San_Pham,
$Hinh ,
$Mo_Ta ,
$Nguoi_Dang ,
$Danh_Gia ,
$link ,
$Ma_Loai ,
$code ,
$yeucau)
    {
        $sql="UPDATE  san_pham SET Ten_San_Pham = $Ten_San_Pham,
Hinh = $Hinh,
Mo_Ta =  $Mo_Ta,
Nguoi_Dang = $Nguoi_Dang,
Danh_Gia = $Danh_Gia,
link =  $link,
Ma_Loai =  $Ma_Loai,
code =  $code,
yeucau =  $yeucau WHERE Ma_San_Pham =$Ma_San_Pham";
        $xldata = new database();
        $kq=$xldata->ExcuteNonquery($sql);
        return $kq;
    }
    
    function Xoa_San_Pham($Ma_San_Pham)
    {
        $sql="delete from san_pham where Ma_San_Pham=$Ma_San_Pham" ;
        $xldata = new database();
        $kq=$xldata->ExcuteNonquery($sql);
        return $kq;
    }
    
    
    
    
    
    
    function Lay_Comment_Moi_Nhat($ma_nguoi_dung)
    {
        $sql="select * from comment where Ngay_Dang='$ma_nguoi_dung' order by Ma_Comment desc";
        $xldata = new database();
        $kq=$xldata->ExcuteObjectList($sql);
        return $kq[0];
    }
    function Lay_Comment_Moi_Nhat_2($ma_anh)
    {
         $sql="select * from Anh inner join kq_comment on Anh.Ma_Anh=kq_comment.Ma_Anh inner join comment on kq_comment.Ma_Comment=comment.Ma_comment where kq_comment.Ma_Anh=$ma_anh order by comment.Ma_Comment desc";
         $xldata = new database();
        $kq=$xldata->ExcuteObjectList($sql);
        return $kq[0];
    }

    function Lay_Thong_Tin_Chi_Tiet_Khong_Co_Comment($ma_anh)
    {
        $sql="select * from Anh where Ma_Anh=$ma_anh";
         $xldata = new database();
        $kq=$xldata->ExcuteObjectList($sql);
        return $kq;
    }
    function Lay_Comment($ma_comment)
    {
        $sql="select * from comment inner join nguoi_dung on comment.Ma_Nguoi_Dung=nguoi_dung.Ma_Nguoi_Dung where comment.Ma_Comment='$ma_comment' ";
        $xldata = new database();
        $kq=$xldata->ExcuteObject($sql);
        return $kq;
    } 
    function Lay_GuessIt()
    {
        //only for user admin
        $sql="select * from Anh where Ma_Nguoi_Dung=1";
        $xldata = new database();
        $kq=$xldata->ExcuteObjectList($sql);
        return $kq;
        
    }
    
}
?>